Xbasic

HTTP_DELETE Function

Syntax

Result as P = http_delete(url as C [,cookie as C [,port as N [,timeout as N [,show_before_send as L [,validate_ssl_cert as L]]]]])

Arguments

urlCharacter

The URL of the page to retrieve.

cookieCharacter

Default = "". Cookie data. Limited to 8 MBytes.

portNumeric

Default = -1. The port to use.

timeoutNumeric

Default = 8000 milliseconds. The number of milliseconds to wait before timing out.

show_before_sendLogical

Default = .F.. When .T., displays the request before being sent. Useful for debugging.

validate_ssl_certLogical

Default = .T.. If the specified URL starts with "https://", this flag controls whether or not the certificate offered by the server will be validated.

Returns

ResultPointer

A dot variable containing the server's response.

error_textCharacter

The error message, if any. If no error occurs, error_text will be empty.

error_codeNumeric

The error number, if any. If no error occurs, error_code will be 0.

headersCharacter

Response headers. If error_code is 0, the result will contain a dot variable, parsed_headers, with a property representing each response header.

bodyCharacter

Response body.

parsed_headersPointer

Contains all the headers in the response split out into individual properties. If an error occurred when trying to communicate with the server, parsed_headers will be empty. parsed_headers will always contain the following properties in addition to the headers in the response:

http_versionCharacter

The HTTP version used.

reason_phraseCharacter

A description of the status code.

status_codeNumeric

The response status code. See Status Codes for a list of status codes.

Description

Use the HTTP method DELETE to retrieve the specified URL

Discussion

The HTTP_DELETE() function requests a URL using the DELETE method with TLS 1.2 or newer.

The function supports cookies and returns a pointer with the parsed response from the server. If error_code is "0", parsed_response will contain the headers in the result:

result = http_delete("www.alphasoftware.com")

? result.error_code
= 0

? result.parsed_headers
= CFRAY = "667102072ce518a1-EWR"
cfrequestid = "0afa7f987a000018a1e31a1000000001"
Connection = "close"
ContentLength = "17"
ContentType = "text/plain;charset=UTF-8"
Date = "Tue, 29 Jun 2021 17:52:19 GMT"
http_version = "HTTP/1.1"
NEL = {"report_to":"cf-nel","max_age":604800}
reason_phrase = "Forbidden"
ReportTo = {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v2?s=fefbfvD1oZR7DXtvijmVUvb359n5gwRK7oMnjrKznNPcgPBhSqn1Mfy%2Bwdmuj%2FWWwtaXKdXGE%2B%2ByISllrhRfsfif9DUYNR0HbB%2FFgIeQ6dNk5oSqAE3FB9CvchoiQtIAON4%3D"}],"group":"cf-nel","max_age":604800}
Server = "cloudflare"
SetCookie = "__cfruid=4b542505c6439ecba2883eb38b3c24660bb358d2-1624989139; path=/; domain=.www.alphasoftware.com; HttpOnly"
status_code = 403

Status code 200 indicates that the page exists. Status code 404 indicates that it does not. Other status codes you may encounter, along with the meanings of each, are documented in Status Codes.

Handling Redirects

When the server responds with a 30* code, HTTP_POST() does not automatically use the new URL. The developer needs to examine result.parsed_headers.status_code, then if appropriate, try the URL provided in result.parsed_headers.location. Refer to HTTP_GET() for an example.

See Also